<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2019/4/2
 * Time: 9:43
 */
namespace app\admin\controller;
use think\Db;
class Freight extends Base {

    public function index(){
        if(request()->isAjax ()){
            extract(input());
            $map['level'] = 2;
            if(isset($district) && $district != ''){
                $map['district'] = ['like', '%' . $district . '%'];
            }
            $Nowpage = input('page') ? input('page'):1;
            $limits = input("limit")?input("limit"):10;// 获取总条数;
            $count = Db::name('area')->where($map)->count();
            $lists = Db::name('area')
                ->page($Nowpage,$limits)
                ->where($map)
                ->select ();
            foreach ($lists as $key=>&$vo){
                 if($vo['status']==1){
                     $vo['name'] = '可以送达';
                 }elseif ($vo['status']==2){
                     $vo['name'] = '不可以送达';
                 }
            }
            return json(['code'=>220,'msg'=>'','count'=>$count,'data'=>$lists]);
        }
        return $this->fetch();
    }

    public function update(){
        if(request()->isPost ()){
            extract(input());
            $id = input('param.id');
            $param = [
                'price'=>input('param.price'),
                'status'=>input('param.status'),
            ];
            $res = Db::name('area')->where('district_id',$id)->update($param);
            if($res){
                return json(['code'=>200,'msg'=>'修改成功']);
            }else{
                return json(['code'=>100,'msg'=>'修改失败']);
            }
        }
        $info = Db::name('area')
            ->where(['district_id'=>input('id')])
            ->find();
        $this->assign('info',$info);
        return $this->fetch();
    }
}